 
 <ul>
		<li class="receive_add addr_item">
		<input value="0" nc_type="addr" id="add_addr" type="radio" name="addr" checked="checked">
		<label for="add_addr">使用新地址</label>
			&nbsp;<!-- <label><a class="del" href="" target="_blank">管理自提服务站 </a></label> -->
		  </li>
		<div id="add_addr_box"><div class="ncc-form-default">
	  <form method="post" id="addr_form" action="{:U('buy/add_address')}">
		<input type="hidden" name="addresshash" id="Infohash" value="">
		<input type="hidden" name="buy_atc" id="buy_atc" value="buy_atc">
		
		<dl>
		  <dt><i class="required">*</i>收货人姓名：</dt>
		  <dd>
			<input type="text" class="text w100" name="true_name" id="true_name" value="">
			<label></label>
		  </dd>
		</dl>
		<dl>
		  <dt><i class="required">*</i>所在地区：</dt>
		  <dd>
			<div id="select">
				<select name="shop_province" id="shop_province">
					<option value="">-请选择-</option>
					<volist name="code" id="vo">
					<option value="{$vo.area_name}" data-id="{$vo.area_id}">{$vo.area_name}</option></volist>
				</select>
				<label></label>
				<input name="province" type="hidden" id="_area_3" value="">
				<input type="hidden" name="city" id="_area_2">
				<input type="hidden" name="area" id="_area">
			</div>
		  </dd>
		</dl>
		<dl>
		  <dt><i class="required">*</i>详细地址：</dt>
		  <dd>
			<input type="text" class="text w500" name="address" id="address"  value="">
			<label></label>
			<p class="hint">请填写真实地址，不需要重复填写所在地区</p>
			
		  </dd>
		</dl>
		<dl>
		  <dt> <i class="required">*</i>手机号码：</dt>
		  <dd>
			<input type="text" class="text w200" name="mob_phone" id="mob_phone"  value="">
			<label></label>&nbsp;&nbsp;(或)&nbsp;固定电话: <input type="text" class="text w200" id="tel_phone" name="tel_phone"  value=""> <label><p class="hint">区号 - 电话号码 - 分机</p></label>
			
		  </dd>
		</dl>
	  </form>
	</div>	 
	</div>
	</ul>
	
	<div class="hr16"> <a id="hide_addr_list" class="ncbtn ncbtn-grapefruit" href="javascript:void(0);">保存收货人信息</a></div>
	
<script>

$().ready(function() {

// 在键盘按下并释放及提交后验证提交表单
  $("#addr_form").validate({
		focusInvalid:false,  
		submitHandler: function(form){  
			form.submit();  
		},
        rules : {
            true_name: {
                required: true,
                maxlength: 20 
            },
            province: {
                required: true,
                maxlength: 4 
            },
            city_id: {
                required: true,
                maxlength: 4 
            },
            area_id: {
                required: true,
                maxlength: 4 
            },
            address: {
                required: true,
                maxlength: 50 
            },
            mob_phone: {
                required: true,
                maxlength: 12 
            },

        },
        messages : {
            true_name: {
                required: '<i class="icon-exclamation-sign"></i>请输入收货人姓名',
                maxlength: jQuery.validator.format("最多{0}个字")
            },
            province: {
                required: '',
                maxlength: jQuery.validator.format("最多{0}个字")
            },
            city_id: {
                required: '',
                maxlength: jQuery.validator.format("最多{0}个字")
            },
            area_id: {
                required: '<i class="icon-exclamation-sign"></i>请选择区域地址',
                maxlength: jQuery.validator.format("最多{0}个字")
            },
            address: {
                required: '<i class="icon-exclamation-sign"></i>请输入详细地址',
                maxlength: jQuery.validator.format("最多{0}个字")
            },
            mob_phone: {
                required: '<i class="icon-exclamation-sign"></i>请输入联系人电话',
                maxlength: jQuery.validator.format("最多{0}个字")
            }
        }
	});

	    $('#hide_addr_list').on('click', function() {
			
			if($('#addr_form').valid()) {
				$('#addr_form').submit();
			}
		});
});
</script>
<script type="text/javascript">
	$(document).ready(function() {
		$('#hide_addr_list').on('click', function() {
			$("#addr_form").submit();
		});
	});

</script>
<script type="text/javascript">

	
$(function(){

	$('input').change(function(){
		$("#Infohash").val(_getRandomString(30));

	});
	$('select').change(function(){
		$("#Infohash").val(_getRandomString(31));
	});
	
	$("select").live('change',function(){
		var option = $(this).val();
		var data_id = $(this).find("option[value='"+option+"']").attr("data-id");
		var next = $(this).next("select").html();         
		var id = $(this).attr('id');
		var name ='city';
		var length = $("select").length;		
		var next_p = '';

		if(id=='shop_province'){
			$("#_area_3").val(option);
			$("#_area_2").val('');
			$("#_area").val('');
		}else if(id=='shop_city') {
			$("#_area_2").val(option);
			$("#_area").val('');
		}else if(id=='shop_area') {
			$("#_area").val(option);
		}
		
		var province = $('#shop_province').val();
		var city = $('#shop_city').val();
		var area = $('#shop_area').val();
		var address = '';	
		
		if (province) {
			address = province;
		}
		if (city==option) {
			address = address +' '+ city;
		} 
		
		if (area==option) {
			address = address +' '+ city +' '+ area;
		}	
		
		if (option) {
			if (next) {
				
				if (length<3) {
					name ='shop_city';
				} else {
					if (id=='shop_province') {						
						name ='shop_city';
						next_p = 1;
					} else {
						name ='shop_area';
					}					
				}
			} else {
				if (length<2) {
					name ='shop_city';					
				} else {
					name ='shop_area';
				}			
			}

			if (id!=='shop_area') {
				get_area(data_id,next,$(this),name,next_p);	
			}						
		} else {			
			$(this).next("select").remove();
		}

	});


});
	//市级、区数据
	function get_area(id,next,option,name,next_p) {
		var url='/Shop/code_chage';		
		$.ajax({
			url:url,
			data:{id:id},
			type:'post',
			dataType:'json',
			success:function (data) {
				var a = data;
				var html = '';
				for(var i=0;i<a.length;i++ ) {								
					html += '<option value ="'+a[i].area_name+'" data-id="'+a[i].area_id+'">'+a[i].area_name+'</option>';
				}
				
				if (html) {
					if (next) {	
						if (next_p) {
							option.nextAll("select").html('<option value="">-请选择-</option>'+html);
							option.next().nextAll("select").remove();
						} else {
							option.next("select").html('<option value="">-请选择-</option>'+html);
						}
						
					} else {
						option.after('<select name="'+name+'" id="'+name+'"><option value="">-请选择-</option>'+html+'</select>');
					}				
				}
				
			}
		});		
	}
	
	// 获取长度为len的随机字符串  
	function _getRandomString(len) {  
		len = len || 32;  
		var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz234567890258413'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1  
		var maxPos = $chars.length;  
		var pwd = '';  
		for (i = 0; i < len; i++) {  
			pwd += $chars.charAt(Math.floor(Math.random() * maxPos));  
		}  
		return pwd;  
	} 
</script> 
